<template>
  <div class="device-wrapper">
    <div class="common-wrapper-top">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>当前位置：</el-breadcrumb-item>
        <el-breadcrumb-item>设备中心</el-breadcrumb-item>
        <el-breadcrumb-item :to="{path: '/devicelist'}">设备管理</el-breadcrumb-item>
        <el-breadcrumb-item>设备详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="commom-top-right">
        <el-button size="mini" @click="RefreshFun" type="primary">刷新</el-button>
        <el-button size="mini" @click="returnBack" type="primary">返回</el-button>
<!--        <el-button size="mini" @click="ceshi" type="primary">一</el-button>-->
      </div>
    </div>
    <div class="common-top-gray-line"></div>
    <div class="device-title-wrapper">
      <div>
        <i class="el-icon-mobile"></i>
        <span>设备信息</span>
      </div>
      <div class="device-two-btn-groups">
        <el-button size="small" @click="card" plain>水卡信息</el-button>
        <el-button size="small" @click="purchasehistory" plain>消费记录</el-button>
      </div>
    </div>
    <div class="device-base">
      <span class="span">设备名称：{{equipment.name}}</span>
      <span class="span">设备编号：{{equipment.number}}</span>
      <span class="span">设备类型：{{equipment.equipment_control_type_desc}}</span>
      <span class="span">安装时间：{{equipment.install_time}}</span>
      <span class="span">园区名称：{{equipment.village_name}}</span>
      <span class=span-width>安装地址：{{equipment.address}}</span>
    </div>
    <div class="common-top-gray-line"></div>
    <div class="device-title-wrapper">
      <div>
        <i class="el-icon-cpu"></i>
        <span>主板信息</span>
      </div>
    </div>
    <div class="mainboard">
      <ul class="mianboard-tabs" v-if=" equipment.equipment_info && equipment.equipment_info.length>1">
        <li @click="switchTab(index)" :class="{active:currentTab==index}"
          v-for="(item,index) in equipment.equipment_info">主板{{index+1}}</li>
      </ul>

      <template v-if="equipment.equipment_info">

        <template v-for="(item,index) in equipment.equipment_info" v-if="currentTab==index" v-key="index">
          <div class="device-base">
            <div class="cell">主板编号：{{item.equipment_number}}</div>
            <div class="cell">主板名称：{{item.equipment_name}}</div>
            <div class="cell">开关机：<span
                :class="item.equipment_status_array.equipment_switchgear.warn?'red_col':''">{{item.status!=1?'--':item.equipment_status_array.equipment_switchgear.desc}}</span>
              <el-button style="margin-left: 10px;" size="mini" :loading="is_option" v-if="item.status==1"
                @click="SwitchOnOff(item.status,item.equipment_status_data.equipment_switchgear)">
                <span v-if="!is_option">{{item.equipment_status_data.equipment_switchgear==1?'开机':'关机'}}</span>
                <span v-else>{{item.equipment_status_data.equipment_switchgear==1?'开机中...':'关机中...'}}</span>
              </el-button>
            </div>

            <div class="cell" v-if="item.door_status!='-2'">开关门：
              <span :class="item.door_status==1?'red_col':''">
                {{item.status!=1?'--':item.door_status==1?'开门':'关门'}}
              </span>
              <el-button style="margin-left: 10px;" size="mini" :loading="is_opening" v-if="item.status==1"
                @click="doorOnOff(item.status,item.door_status)">
                <span v-if="!is_opening">{{item.door_status==0?'开门':'关门'}}</span>
                <span v-else>{{item.door_status==0?'开门中...':'关门中...'}}</span>
              </el-button>
            </div>

            <div class="cell" v-if="item.second_door_status!='-2'">开关加注门：
              <span :class="item.second_door_status==1?'red_col':''">
                {{item.status!=1?'--':item.second_door_status==1?'开门':'关门'}}
              </span>
              <el-button style="margin-left: 10px;" size="mini" :loading="is_opening_second" v-if="item.status==1"
                         @click="SeconddoorOnOff(item.status,item.second_door_status)">
                <span v-if="!is_opening_second">{{item.second_door_status==0?'开门':'关门'}}</span>
                <span v-else>{{item.second_door_status==0?'开门中...':'关门中...'}}</span>
              </el-button>
            </div>

            <div class="cell">联网状态：<span :class="item.status==2?'red_col':''">{{ item.status_desc}}</span>
            </div>
            <div class="cell" v-if="item.status==2 && item.off_line_time">离线时间：<span>{{ item.off_line_time}}</span>
            </div>
            <div class="cell">主板状态：
              <span :class="item.equipment_status_array.equipment_status.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_status.desc}}</span>
            </div>

            <div class="cell">售水状态：<span
                :class="item.equipment_status_array.equipment_water_selling_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_water_selling_state.desc}}</span>
            </div>

            <div class="cell">内部加热状态：<span
                :class="item.equipment_status_array.equipment_internal_heating_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_internal_heating_state.desc}}</span>
            </div>

            <div class="cell">水位状态：<span
                :class="item.equipment_status_array.equipment_water_level_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_water_level_state.desc}}</span>
            </div>


            <div class="cell">源水TDS：<span
                :class="item.equipment_status_array.equipment_source_water_TDS.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_source_water_TDS.desc}}（mg/L）</span>
            </div>

            <div class="cell">冲洗开关状态：<span
                :class="item.equipment_status_array.equipment_flush_switch_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_flush_switch_state.desc}}</span>
            </div>

            <div class="cell">门开关状态：<span
                :class="item.equipment_status_array.equipment_gate_switch_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_gate_switch_state.desc}}</span>
            </div>

            <div class="cell">外部水压：<span
                :class="item.equipment_status_array.equipment_external_water_pressure.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_external_water_pressure.desc}}</span>
            </div>


            <div class="cell">纯水TDS：<span
                :class="item.equipment_status_array.equipment_pure_water_TDS.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_pure_water_TDS.desc}}（mg/L）</span>
            </div>


            <div class="cell">运行开关状态：<span
                :class="item.equipment_status_array.equipment_running_switch_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_running_switch_state.desc}}</span>
            </div>

            <div class="cell">外部加热状态：<span
                :class="item.equipment_status_array.equipment_external_heating_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_external_heating_state.desc}}</span>
            </div>

            <div class="cell">温度：<span
                :class="item.temperature_status!=1&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_temperature.desc}}℃</span>
            </div>

            <div class="cell">制水状态：<span
                :class="item.equipment_status_array.equipment_water_making_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_water_making_state.desc}}</span>
            </div>

            <div class="cell">保温开关状态：<span
                :class="item.equipment_status_array.equipment_insulation_switch_state.warn&&item.status==1?'red_col':''">{{ item.status!=1?'--':item.equipment_status_array.equipment_insulation_switch_state.desc}}</span>
            </div>
          </div>
          <div class="mainboard-btns">
            <el-button size="small" type="primary" icon="el-icon-s-custom" @click="custom" plain>用户信息</el-button>
            <el-button size="small" type="primary" icon="el-icon-connection" @click="connect" plain>连接记录</el-button>
            <el-button size="small" type="primary" icon="el-icon-takeaway-box" @click="filterCoreRecord" plain>换芯记录
            </el-button>
            <el-button size="small" type="primary" icon="el-icon-set-up" @click="exchangeMainboard" plain>替换主板
            </el-button>
            <el-button size="small" type="primary" icon="el-icon-notebook-2" @click="exchangeMainboardRecord" plain>
              主板替换记录</el-button>
          </div>

          <div class="table_box">
            <div class="table-head">
              <div class="table-head-title" :class="children[index]==1?'table-active':''" @click="checkTable(1,index)">
                系统参数
              </div>
              <div class="table-head-title" :class="children[index]==2?'table-active':''" @click="checkTable(2,index)">
                售水参数
              </div>
              <div class="table-head-title" :class="children[index]==3?'table-active':''" @click="checkTable(3,index)">
                制水参数
              </div>
              <div class="table-head-title" :class="children[index]==4?'table-active':''" @click="checkTable(4,index)">
                控制参数
              </div>
              <div class="table-head-title" v-if="item.screen_param.length>0" :class="children[index]==5?'table-active':''" @click="checkTable(5,index)">
                屏幕设置
              </div>
            </div>



            <div class="common-table-outer" v-if="children[index]==1">
              <el-table class="common-table" header-cell-class-name="common-table-header-cell"
                :data="item.equipment_param.sys">
                <el-table-column align="center" prop="name" label="参数名称">
                </el-table-column>

                <el-table-column align="center" prop="name" label="单位">
                  <template slot-scope="scope">
                    {{scope.row.unit||'--'}}
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="设定值">
                  <template slot-scope="scope">
                    <div v-if="scope.row.type=='radio'">
                      <el-radio-group v-model="scope.row.value" fill="#2C5586">
                        <el-radio :label="item.value" v-for="(item,index) in scope.row.option" :key="index">
                          {{item.name}}
                        </el-radio>
                      </el-radio-group>
                    </div>
                    <div v-else-if="scope.row.type=='date'">
                      <el-date-picker style="width:190px" v-model="scope.row.value" type="datetime" size="medium"
                        value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择时间"></el-date-picker>
                    </div>
                    <div class="operationInput" v-else>
                      <el-input-number v-model="scope.row.value" :min="scope.row.min?scope.row.min:0"
                        :max="scope.row.max?scope.row.max:999999"></el-input-number>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作">
                  <template slot-scope="scope">
                    <el-button size="medium" plain type="primary"
                      @click="refreshSure('sys',scope.row.id,scope.row.value)">
                      点击下发</el-button>
                  </template>
                </el-table-column>

              </el-table>
            </div>






            <div class="common-table-outer" v-if="children[index]==2">
              <el-table class="common-table" header-cell-class-name="common-table-header-cell"
                :data="item.equipment_param.sale_water">
                <el-table-column align="center" prop="name" label="参数名称">
                </el-table-column>

                <el-table-column align="center" prop="name" label="单位">
                  <template slot-scope="scope">
                    {{scope.row.unit||'--'}}
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="设定值">
                  <template slot-scope="scope">
                    <div v-if="scope.row.type=='radio'">
                      <el-radio-group v-model="scope.row.value" fill="#2C5586">
                        <el-radio :label="item.value" v-for="(item,index) in scope.row.option" :key="index">
                          {{item.name}}
                        </el-radio>
                      </el-radio-group>
                    </div>
                    <div class="operationInput" v-else>
                      <el-input-number v-model="scope.row.value" :min="0"></el-input-number>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作">
                  <template slot-scope="scope">
                    <el-button size="medium" plain type="primary"
                      @click="refreshSure('sale_water',scope.row.id,scope.row.value)">点击下发</el-button>
                  </template>
                </el-table-column>

              </el-table>
            </div>





            <div class="common-table-outer" v-if="children[index]==3">
              <el-table class="common-table" header-cell-class-name="common-table-header-cell"
                :data="item.equipment_param.system_water">
                <el-table-column align="center" prop="name" label="参数名称">
                </el-table-column>

                <el-table-column align="center" prop="name" label="单位">
                  <template slot-scope="scope">
                    {{scope.row.unit||'--'}}
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="设定值">
                  <template slot-scope="scope">
                    <div v-if="scope.row.type=='radio'">
                      <el-radio-group v-model="scope.row.value" fill="#2C5586">
                        <el-radio :label="item.value" v-for="(item,index) in scope.row.option" :key="index">
                          {{item.name}}
                        </el-radio>
                      </el-radio-group>
                    </div>
                    <div v-else-if="scope.row.type=='time'">
                      <el-time-picker style="width:190px" v-model="scope.row.desc" size="medium" value-format="HH:mm"
                        format="HH:mm" placeholder="选择时间"></el-time-picker>
                    </div>
                    <div class="operationInput" v-else>
                      <el-input-number v-model="scope.row.value" v-if="scope.row.id=='06' || scope.row.id=='07'">
                      </el-input-number>
                      <el-input-number v-model="scope.row.value" :min="0" v-else></el-input-number>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作">
                  <template slot-scope="scope">
                    <el-button size="medium" v-if="scope.row.type=='time'" plain type="primary"
                      @click="refreshSure('system_water',scope.row.id,scope.row.desc,1)">点击下发</el-button>
                    <el-button size="medium" v-else plain type="primary"
                      @click="refreshSure('system_water',scope.row.id,scope.row.value)">点击下发</el-button>
                  </template>
                </el-table-column>

              </el-table>
            </div>

            <div class="common-table-outer" v-if="children[index]==4">
              <el-table class="common-table" header-cell-class-name="common-table-header-cell"
                :data="item.equipment_param.control">
                <el-table-column align="center" prop="name" label="参数名称">
                </el-table-column>

                <el-table-column align="center" prop="name" label="单位">
                  <template slot-scope="scope">
                    {{scope.row.unit||'--'}}
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="设定值">
                  <template slot-scope="scope">
                    <div v-if="scope.row.type=='radio'">
                      <el-radio-group v-model="scope.row.value" fill="#2C5586">
                        <el-radio :label="item.value" v-for="(item,index) in scope.row.option" :key="index">
                          {{item.name}}</el-radio>
                      </el-radio-group>
                    </div>
                    <div class="operationInput" v-else>
                      <el-input-number v-model="scope.row.value" :min="0"></el-input-number>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作">
                  <template slot-scope="scope">
                    <el-button size="medium" plain type="primary"
                      @click="refreshSure('control',scope.row.id,scope.row.value)">点击下发</el-button>
                  </template>
                </el-table-column>

              </el-table>
            </div>


            <div class="common-table-outer" v-if="children[index]==5 && item.screen_param.length>0">
              <el-table class="common-table" header-cell-class-name="common-table-header-cell"
                :data="item.screen_param">
                <el-table-column align="center" prop="name" label="参数名称">
                </el-table-column>
                <!-- <el-table-column align="center" label="单位">
                  <template slot-scope="scope">
                     {{scope.row.unit||'--'}}
                  </template>
                </el-table-column> -->
                <el-table-column align="center" label="设定内容">
                  <template slot-scope="scope">
                    <div v-if="scope.row.type=='img'">
                      <!-- <img :src="scope.row.value" width="20" height="20" alt=""> -->
                      <div>{{scope.row.name}}</div>
                    </div>
                    <div v-else>
                       <el-input v-model="scope.row.value" :disabled="scope.row.id=='02'" :placeholder="'请输入'+ scope.row.name"></el-input>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="name" label="操作">
                  <template slot-scope="scope">
                    <el-button size="medium" plain type="primary"
                      @click="refreshSure('screen_param',scope.row.instruction,scope.row.value)">点击下发</el-button>
                  </template>
                </el-table-column>

              </el-table>
            </div>
          </div>
        </template>
      </template>
      <div>
      </div>
    </div>

    <el-dialog title="替换主板" :close-on-click-modal="false" top="30vh"
      custom-class="mainboard-custom-dialog common-custom-dialog" center :visible.sync="dialogFormVisible">

      <div class="mainboard-dialog-wrapper" v-if="equipment.equipment_info.length>0">
        <div class="mainboard-dialog-row">
          <label>原主板编号</label>
          <el-input size="medium" disabled v-model="equipment.equipment_info[currentTab].equipment_number"></el-input>
        </div>

        <div class="mainboard-dialog-row">
          <label>主板编号</label>
          <el-input size="medium" v-model="replace_number" placeholder="请输入主板编号"></el-input>
        </div>


        <span slot="footer" class="dialog-footer">
          <el-button @click="hideModel()">取 消</el-button>
          <el-button type="primary" @click="replace">替 换</el-button>
        </span>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: "moreinformation",
    data() {
      return {
        currentTab: 0,
        equipment_control_id: "",
        equipment: {equipment_info:[]},
        children: [],
        dialogFormVisible: false,
        replace_number: '',
        is_option: false,
        is_opening:false,
        mianboardId:'',//当前主板ID
      }
    },
    created() {
      this.equipment_control_id = this.$route.query.id;
      this.getEquipment();
    },
   // nextTick(callback, context) {
   //    console.log('equipment',equipment)
   // },
    inject: [
			'reload'
		],

    methods: {

      RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
      },

      ceshi() {
        var that = this;
        // ajax请求
        that.$post({
          url: 'Manage/Equipment/eq_text',
          data: {},
          success: data => {
            console.log(data);
          }
        });
      },
      //开关门
      SeconddoorOnOff(online, offType){
        if (online != 1) {
          this.$message({ showClose: true, center: true, type: 'error', message: '设备已经离线,无法执行操作' });
          return false;
        }
        var textShow = offType == 0 ? '是否开启加注门?' : '是否关闭加注门';
        var typeiCon = offType == 0 ? 'success' : 'error';
        var iconClass = offType == 0 ? 'el-icon-open' : 'el-icon-turn-off';
        this.$confirm('', textShow, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center: true,
          type: typeiCon,
          iconClass,
        }).then(() => {
          this.is_opening_second = true;
          this.openClose(offType == 1 ? 0 : 1,3);
        }).catch(() => {
          this.$message({
            center: true,
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //开关门
      doorOnOff(online, offType){
        if (online != 1) {
          this.$message({ showClose: true, center: true, type: 'error', message: '设备已经离线,无法执行操作' });
          return false;
        }
        var textShow = offType == 0 ? '是否开门?' : '是否关门';
        var typeiCon = offType == 0 ? 'success' : 'error';
        var iconClass = offType == 0 ? 'el-icon-open' : 'el-icon-turn-off';
        this.$confirm('', textShow, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center: true,
          type: typeiCon,
          iconClass,
        }).then(() => {
          this.is_opening = true;
          this.openClose(offType == 1 ? 0 : 1,2);
        }).catch(() => {
          this.$message({
            center: true,
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //开关机 1关机 2开机
      SwitchOnOff(online, offType) {
        if (online != 1) {
          this.$message({ showClose: true, center: true, type: 'error', message: '设备已经离线,无法执行操作' });
          return false;
        }
        // console.log('offType',offType,online);
        var textShow = offType == 1 ? '是否开机?' : '是否关机';
        var typeiCon = offType == 1 ? 'success' : 'error';
        var iconClass = offType == 1 ? 'el-icon-open' : 'el-icon-turn-off';
        this.$confirm('', textShow, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center: true,
          type: typeiCon,
          iconClass,
        }).then(() => {
          this.is_option = true;
          this.openClose(offType == 1 ? 2 : 1,1);
        }).catch(() => {
          this.$message({
            center: true,
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //开关机post请求 //typeC 1开关机 2开门
      openClose(value,typeC) {
        let that = this;
        let url='';
        //let url=typeC==2?'Common/Equipment/controlDoor':'Partner/Equipment/switchgear';
        if(typeC==2){
            url = 'Common/Equipment/controlDoor';
        }else if(typeC==3){
            url = 'Common/Equipment/controlSecondDoor';
        }else{
            url = 'Partner/Equipment/switchgear';
        }
        console.log(1111);
        console.log('url',url)
        let upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            val: value,
          };
        if(typeC==2){
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            status: value,
          }
        }
        if(typeC==3){
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            status: value,
          }
        }
        console.log(typeC)
        // console.log(url)
        console.log(that.equipment.equipment_info[that.currentTab].equipment_number)
        console.log(value)

        that.$post({
          url,
          data:upData,
          success: (data) => {
            console.log('成功')
            console.log('>>>>', data)
            this.is_option = false;
            this.is_opening= false;
            this.is_opening_second= false;
            var types = 'info';
            if (data.code == 1000) {
              if(typeC==1){
                  that.equipment.equipment_info[that.currentTab].equipment_status_data.equipment_switchgear = value == 1 ? 1 : 2;
                  that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.value = value == 1 ? 1 : 2;
                  that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.warn = value == 1 ? true : false;
                  that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.desc = value == 1 ? "关机" : "开机";
                  var types = 'success';
              }else if(typeC==2){
                that.equipment.equipment_info[that.currentTab].door_status=value == 1 ? 1 : 0;
              }else if(typeC==3){
                that.equipment.equipment_info[that.currentTab].second_door_status=value == 1 ? 1 : 0;
              }

            }
            this.$message({
              showClose: true,
              message: data.message,
              type: types,
              center: true
            });
          },
          error:(res)=>{
            console.log('错误')
            this.is_option = false;
            this.is_opening= false;
            this.is_opening_second= false;
          }
        })
      },


      /****新增start****/
      //开关门 1关门 2开门
      SwitchDoor(online, offType) {
        if (online != 1) {
          this.$message({ showClose: true, center: true, type: 'error', message: '设备已经离线,无法执行操作' });
          return false;
        }
        // console.log('offType',offType,online);
        var textShow = offType == 1 ? '是否开门?' : '是否关门';
        var typeiCon = offType == 1 ? 'success' : 'error';
        var iconClass = offType == 1 ? 'el-icon-open' : 'el-icon-turn-off';
        this.$confirm('', textShow, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center: true,
          type: typeiCon,
          iconClass,
        }).then(() => {
          this.is_option = true;
          this.SwitchDoorRequest(offType == 1 ? 2 : 1);
        }).catch(() => {
          this.$message({
            center: true,
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //开关门post请求
      SwitchDoorRequest(value) {
        var that = this;
        that.$post({
          url: 'Partner/Equipment/door_switchgear',
          data: {
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            val: value,
          },
          success: (data) => {
            console.log('>>>>', data)
            this.is_option = false;
            var types = 'info';
            if (data.code == 1000) {
              that.equipment.equipment_info[that.currentTab].equipment_status_data.equipment_switchgear = value == 1 ? 1 : 2;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.value = value == 1 ? 1 : 2;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.warn = value == 1 ? true : false;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.desc = value == 1 ? "关机" : "开机";
              var types = 'success';
            }
            this.$message({
              showClose: true,
              message: data.message,
              type: types,
              center: true
            });
          }
        })
      },


      //加注门开关 1关机 2开机
      SwitchSecondDoor(online, offType) {
        if (online != 1) {
          this.$message({ showClose: true, center: true, type: 'error', message: '设备已经离线,无法执行操作' });
          return false;
        }
        // console.log('offType',offType,online);
        var textShow = offType == 1 ? '是否开启加注门?' : '是否关闭加注门';
        var typeiCon = offType == 1 ? 'success' : 'error';
        var iconClass = offType == 1 ? 'el-icon-open' : 'el-icon-turn-off';
        this.$confirm('', textShow, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          center: true,
          type: typeiCon,
          iconClass,
        }).then(() => {
          this.is_option = true;
          this.SwitchSecondDoorRequest(offType == 1 ? 2 : 1);
        }).catch(() => {
          this.$message({
            center: true,
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //加注门开关post请求
      SwitchSecondDoorRequest(value) {
        var that = this;
        that.$post({
          url: 'Partner/Equipment/second_door_switchgear',
          data: {
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            val: value,
          },
          success: (data) => {
            console.log('>>>>', data)
            this.is_option = false;
            var types = 'info';
            if (data.code == 1000) {
              that.equipment.equipment_info[that.currentTab].equipment_status_data.equipment_switchgear = value == 1 ? 1 : 2;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.value = value == 1 ? 1 : 2;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.warn = value == 1 ? true : false;
              that.equipment.equipment_info[that.currentTab].equipment_status_array.equipment_switchgear.desc = value == 1 ? "关机" : "开机";
              var types = 'success';
            }
            this.$message({
              showClose: true,
              message: data.message,
              type: types,
              center: true
            });
          }
        })
      },
      /****新增end****/


      //下发提交参数设置
      refreshSure(key, id, value, sysother) {
        var that = this;
        var _url = '';
        if (key == 'control') {
          _url = 'Manage/Equipment/controlParamEdit';
        } else if (key == 'sale_water') {
          _url = 'Manage/Equipment/saleWaterParamEdit';
        } else if (key == 'sys') {
          _url = 'Manage/Equipment/systemParamEdit';
        } else if (key == 'system_water') {
          _url = 'Manage/Equipment/waterMakingParamEdit';
        }else if(key=='screen_param'){
          _url = 'Common/Equipment/setScreenParam';
        }
        let upData={};
        //屏幕
        if(key=='screen_param'){
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            instruction: id,
            content: value,
          }
        }else{
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            param: id,
            value: value,
          }
        }
        if (sysother == 1) {
          value = value.replace(new RegExp(/(:)/g), "");
        }
        that.$post({
          url: _url,
          data: upData,
          success: (data) => {
            console.log("下发成功")
            if(key!=='screen_param'){
              setTimeout(()=>{
                let count=0;
                if(count<5){
                  this.refreshSureUpdate(key, id, value, sysother);
                  count++;
                } else {
                  this.$message({
                    showClose: true,
                    message: "更新超时",
                    center: true
                  });
                }
              },2000)
            }else{
              this.$message({
                showClose: true,
                message: data.message,
                center: true
              });
            }
          }
        })
      },

      //下发参数更新检测
      refreshSureUpdate(key, id, value, sysother) {
        console.log("进行检测")
        var that = this;
        var _url = '';
        if (key == 'control') {
          _url = 'Manage/Equipment/controlParamEditcheck';
        } else if (key == 'sale_water') {
          _url = 'Manage/Equipment/saleWaterParamEditcheck';
        } else if (key == 'sys') {
          _url = 'Manage/Equipment/systemParamEditcheck';
        } else if (key == 'system_water') {
          _url = 'Manage/Equipment/waterMakingParamEditcheck';
        }else if(key=='screen_param'){
          //屏幕参数控制是根据下发状态更改数据库，流程是同步进行，不用执行检测
          _url = 'Common/Equipment/setScreenParamcheck';
        }
        let upData={};
        //屏幕
        if(key=='screen_param'){
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            instruction: id,
            content: value,
          }
        }else{
          upData={
            sn: that.equipment.equipment_info[that.currentTab].equipment_number,
            param: id,
            value: value,
          }
        }
        if (sysother == 1) {
          value = value.replace(new RegExp(/(:)/g), "");
        }
        console.log(upData)
        that.$post({
          url: _url,
          data: upData,
          success: (data) => {
            console.log(data.message)
            this.$message({
              showClose: true,
              message: data.message,
              center: true
            });
          }
        })
      },

      getEquipment() {
        this.$post({
          url: "Partner/Equipment/detail",
          data: {
            equipment_control_id: this.equipment_control_id,
          }, success: res => {
            if (res.code > 0) {
              console.log(res.data)
              this.equipment = res.data;
              this.mianboardId= res.data.equipment_info[this.currentTab].id;
              let equipment_info = res.data.equipment_info;
              let children = [];
              for (let i = 0; i < equipment_info.length; i++) {
                children.push(1);
              }
              this.children = children;
            } else {
              this.$message.error(res.message);
            }
          }, error: e => {
            this.$message.error("网络错误");
          }
        })
      },

      //连接记录
      connect() {
        this.$router.push({ path: '/connection', query: { equipment_number: this.equipment.equipment_info[this.currentTab].equipment_number } });
      },
      //用户列表
      custom() {
        this.$router.push({ path: '/deviceuserlist', query: { equipment_number: this.equipment.equipment_info[this.currentTab].equipment_number } });
      },
      //滤芯更换记录
      filterCoreRecord() {

        this.$router.push({ path: '/corechangerecord', query: { equipment_number: this.equipment.equipment_info[this.currentTab].equipment_number } });

      },

      //替换主板
      exchangeMainboard() {
        this.replace_number = "";
        this.dialogFormVisible = true;
      },

      replace() {
        if (this.replace_number == '') {
          this.$message.error("请输入主板编号");
          return false;
        }
        this.$confirm('确认替换该主板, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$post({
            url: "Partner/Equipment/replaceNumber",
            data: {
              equipment_id: this.mianboardId,
              equipment_number: this.equipment.equipment_info[this.currentTab].equipment_number,
              new_number: this.replace_number
            }, success: res => {
              if (res.code > 0) {
                this.$message.success(res.message);
                this.dialogFormVisible = false;
                 this.getEquipment();
              } else {
                this.$message.error(res.message);
              }
            },
            error: e => {
              this.$message.error("网络错误");
            }
          })
        }).catch(() => {

        });
      },

      hideModel() {
        this.dialogFormVisible = false;
      },
      //主板替换记录
      exchangeMainboardRecord() {
        this.$router.push({ path: '/replace_list', query: { equipment_number: this.equipment.equipment_info[this.currentTab].equipment_number } })
      },


      //水卡信息
      card: function () {
        this.$router.push({ path: '/devicecardlist', query: { equipment_id:  this.mianboardId  } });
      },

      // 消费记录
      purchasehistory: function () {
        this.$router.push({ path: '/purchasehistory', query: { equipment_id:  this.mianboardId  } });
      },

      switchTab(index) {
        this.currentTab = index;
        this.mianboardId=this.equipment.equipment_info[index].id;
      },

      // 切换参数表
      checkTable(num, index) {
        this.$set(this.children, index, num);
      },

      //返回
      returnBack() {
        this.$router.back(-1);
      },
    },

  }
</script>
<style scoped>
  .device-title-wrapper {
    display: flex;
    color: #2C5586;
    font-weight: bold;
    padding: 30px 60px 10px 30px;
    align-items: center;
    justify-content: space-between;
    position: relative;
  }

  .device-title-wrapper::before {
    content: "";
    bottom: 0;
    position: absolute;
    border-bottom: 1px solid #F2F2F2;
    width: 96%;
  }

  .device-base {
    position: relative;
    width: 96%;
    margin: 0 auto;
    padding-top: 20px;
    display: flex;
    flex-wrap: wrap;
    font-size: 14px;
    color: #4D4D4D;
    padding-bottom: 20px;
  }

  .device-base .cell {
    width: 25%;
    margin-bottom: 15px;
  }



  .device-base .span {
    display: block;
    width: 25%;
    margin-bottom: 15px;
  }

  .span-width {
    width: 50% !important;
  }

  .mainboard {
    padding: 0 30px 30px;
  }

  .mianboard-tabs {
    padding: 0;
    display: inline-block;
    background: #E9F3FF;
    border-radius: 16px;
    overflow: hidden;
    margin-top: 20px;
    margin-bottom: 0;
  }

  .mianboard-tabs li {
    float: left;
    color: #2C5586;
    padding: 5px 20px;
    cursor: pointer;
    font-size: 15px;
    transition: all .3s cubic-bezier(.645, .045, .355, 1);
  }

  .mianboard-tabs .active {
    background: #2C5586;
    color: #fff;
    border-radius: 16px;
  }

  .red_col {
    color: #FF6565 !important;
  }

  /* 设备参数 */
  .table_box {
    position: relative;
  }
  .device-wrapper .table_box{
    min-height: 320px;
  }
  .table-head {
    border-bottom: 1px solid #EDEDED;
    display: flex;
    align-items: center;
    margin-bottom: 20px;
  }

  .table-head-title {
    width: 120px;
    height: 46px;
    line-height: 46px;
    text-align: center;
    color: #808080;
    margin-right: 10px;
    cursor: pointer;
    text-align: center;
  }

  .table-active {
    color: #2C5586;
    background: #fff;
    border: 1px solid #EDEDED;
    border-bottom: none;
    box-sizing: border-box;
    border-bottom: 2px solid #2C5586;
  }

  .mainboard-btns {
    margin-top: -10px;
    margin-bottom: 20px;
  }

  .dialog-footer {
    display: flex;
    justify-content: center;
  }

  .mainboard-dialog-row {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
  }

  .mainboard-dialog-row label {
    width: 100px;
  }
</style>
<style>
  .mainboard-custom-dialog {
    width: 500px !important;
  }
</style>
